var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
$(function(){
	var usercode = $("#user-name",parent.parent.document).attr("code");
	var userkey = $("#user-name",parent.parent.document).attr("key");
	var usertype = $("#user-name",parent.parent.document).attr("usertype");
	keyCheck(usercode,usertype,userkey,function(){
		initSmPages();
		window.onresize = function () {
			initSmPages();
		};
		pageBtns();
		getCaller();
	});
});
function getCaller(){
	var userKey = $("#user-name",parent.parent.document).attr("key");
	var imei = $(".students-choice-select",parent.document).attr("imei");
	var data = {
			cmd:"getCard",
			model:"card",
			userKey:userKey,
			data:{
				imei:imei,
			},
			remark:"",
	};
	AjaxCrud.add(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1 && res.data != undefined && res.data != ""){
			var list = res.data;
			if(list.length > 0){
				var radios = $("input[name='card-model']");
				if(list[0].model != "" && list[0].model != null && list[0].model != undefined){
					for(var i = 0; i < radios.length; i++){
						if(radios[i].value == list[0].model){
							radios[i].checked = true;
						} 
					}
				}else{
					radios[0].checked = true;
				}
			}
		}else{
			var radios = $("input[name='card-model']");
			for(var i = 0; i < radios.length; i++){
				radios[i].checked = false;
			}
		}
	},null,null);
}
function addCaller(){
	var imei = $(".students-choice-select",parent.document).attr("imei");
	var userKey = $("#user-name",parent.parent.document).attr("key");
	var model = $("input[name='card-model']:checked").val();
	var data = {
			cmd:"updateCard",
			model:"card",
			userKey:userKey,
			data:{
				imei:imei,
				model:model,
			},
			remark:"",
	};
	processBegin("正在应用中···");
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
		if(res.result == 1 && res.data != undefined && res.data != ""){
			processEnd("设置成功");
			getCaller();
		}else{
			processError("设置失败");
		}
	},null,null);
}
function pageBtns(){
	$(".students-choice",parent.document).unbind("click");
	$(".students-choice",parent.document).click(function(){
		$(".students-choice",parent.document).removeClass("students-choice-select");
		$(this).addClass("students-choice-select");
		getCaller();
	});
	$("#caller-set").click(function(){
		addCaller();
	});
}
function initSmPages(){
	var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
	$(".right-content").height(rcH);
	
	var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
	$(".content-data-show").height(cdsH);
}